<%@ include file="/WEB-INF/jsp/includes.jsp" %>
<%@ include file="/WEB-INF/jsp/header.jsp" %>
<link rel="STYLESHEET" type="text/css" href="/admin/style/dhtmlxtree_std.css">
<script  src="/admin/js/dhtmlxtree_std.js"></script>
<script type="text/javascript">
var tree;
var lastBid;
function showhdrs(bid) {
  if (tree != null) {
    tree.deleteChildItems(0);
    if (lastBid == bid) {
        lastBid = '';
        return;
    }
  }
  tree = new dhtmlXTreeObject('hdr' + bid, '100%', '100%', 0);
  tree.setSkin('dhx_skyblue');
  tree.setImagePath('/admin/imgs/csh_bluefolders/');
  tree.enableDragAndDrop(false);
  tree.enableHighlighting(true);
  tree.loadXML('/admin/getBundleHdrs.do?ID=' + bid);
  lastBid = bid;
}
function bundleOp(op, bundleId) {
  dhtmlxAjax.get('/admin/bundleOp.do?OP=' + op + '&ID=' + bundleId, function(ld) {
    alert(ld.xmlDoc.responseText);
    window.location = '/admin/bundles.do';
  });
}
</script>
</head>
<body>
<center>
<c:forEach var="bundle" items="${bundleModel.bundles}" varStatus="ls">
  <table id="bundles">
    <c:if test="${ls.index == 0}">
      <tr>
        <th><fmt:message key="bundle.bundleId"/></th>
        <th><fmt:message key="bundle.symName"/></th>
        <th><fmt:message key="bundle.version"/></th>
        <th><fmt:message key="bundle.state"/></th>
        <th><fmt:message key="bundle.artifact"/></th>
        <th><fmt:message key="bundle.lastModified"/></th>
        <th><fmt:message key="bundle.action"/></th>
      </tr>
    </c:if>
    <tr class="${ls.index % 2 == 0 ? 'even' : 'odd'}">
      <td width="3%">${bundle.id}</td>
      <td width="29%"><a href="JavaScript:void" onclick="showhdrs('${ls.index}')">${bundle.symbolicName}</a></td>
      <td width="10%">${bundle.version}</td>
      <td width="7%">${bundle.state}</td>
      <td width="30%">${bundle.location}</td>
      <td width="16%">${bundle.lastModified}</td>
      <td width="5%">
        <c:if test="${bundle.state == 'RESOLVED' && !bundle.isFragment}">
          <img src="/admin/imgs/play-icon.png" onclick="bundleOp('START', ${bundle.id});"/>
        </c:if>
        <c:if test="${bundle.state == 'ACTIVE'}">
          <img src="/admin/imgs/stop-icon.png" onclick="bundleOp('STOP', ${bundle.id});"/>
        </c:if>
        <c:if test="${bundle.state != 'UNINSTALLED'}">
          <img src="/admin/imgs/Eject-icon.png" onclick="bundleOp('EJECT', ${bundle.id});"/>
        </c:if>
      </td>
    </tr>
  </table>
  <div id="hdr${ls.index}"></div>
</c:forEach>
</center>
</body>
</html>
